package stripsLanguage;

import java.util.ArrayList;
import java.util.List;

/**
 * opis operatora jezyka STRIPS
 * 
 * UWAGA!
 * 
 * Zapisane w Step, po ktorym Operator dziedziczy, identyfikatory obiektow w predykatach
 * to nie id Instancji, ale oznaczenia obiektow w ramach tego operatora (zaleznosci miedzy
 * predykatami)
 * 
 * @author Lukasz
 *
 */

public class Operator {
	
	/** name of the operator **/
	protected String Name;
	
	/** type of operator **/
	protected int TypeOfOperator;
	
	/** list of preconditions of the operator**/
	protected List<Predicate> Preconditions = null;
	
	/** list of effects of the operator **/
	protected List<Predicate> Effects = null;
	
	
	public Operator(
		int typeOfOperator,
		String name,
		List<Predicate> preconditions,
		List<Predicate> effects)
	{
		TypeOfOperator = typeOfOperator;
		Name = name;
		Preconditions = preconditions;
		Effects = effects;
	}

	public List<Predicate> getEffects()
	{
		return Effects;
	}
	
	public List<Predicate> getPreconditions()
	{
		return Preconditions;
	}

	public String getName() {
		return Name;
	}

	public int getTypeOfOperator()
	{
		return TypeOfOperator;
	}

	public List<Predicate> copyEffects()
	{
		return copyList(Effects);
	}

	public List<Predicate> copyPreconditions()
	{
		return copyList(Preconditions);
	}
	
	
	private List<Predicate> copyList(List<Predicate> listToBeCopied)
	{
		List<Predicate> list = new ArrayList<Predicate>();
		for(Predicate p: listToBeCopied)
			list.add(p.copyPredicateForOperator());
		return list;
	}
	
	public String toString()
	{		
		String s = "\n\t(" + TypeOfOperator + "," + getName() + ") ";
		s += "\n\t[PREC ";
		if(Preconditions != null)
			for (Predicate p: Preconditions)
				try {
					s += p.toString(true);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		s += "] ";
		
		s += "\n\t[EFF ";
		if(Effects != null)
			for (Predicate p: Effects)
				try {
					s += p.toString(true);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		s += "] ";
		return s;
	}
}
